
def dict_to_lua(data, indent=0):
    """
    将 Python 字典递归转换为 Lua 表格式字符串
    """
    lua_str = ""
    indent_space = "    " * indent  # 每一级缩进为4个空格

    if isinstance(data, dict):
        lua_str += "{\n"
        for key, value in data.items():
            lua_key = f'["{key}"]' if isinstance(key, str) else f"[{key}]"
            lua_value = dict_to_lua(value, indent + 1)
            lua_str += f"{indent_space}    {lua_key} = {lua_value},\n"
        lua_str += f"{indent_space}}}"
    elif isinstance(data, list):
        lua_str += "{\n"
        for value in data:
            lua_value = dict_to_lua(value, indent + 1)
            lua_str += f"{indent_space}    {lua_value},\n"
        lua_str += f"{indent_space}}}"
    elif isinstance(data, str):
        lua_str += f'"{data}"'
    elif isinstance(data, (int, float, bool)):
        lua_str += str(data).lower()  # Lua 中的 true/false 是小写
    else:
        lua_str += "nil"  # 其他类型用 nil 表示
    return lua_str